package com.atguigu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Description
 * @Author codingBee
 * @Date 2020/4/28/20:54
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @PostMapping("/login")
    public String login(@RequestParam String username, @RequestParam String password, Map<String,Object> map, HttpSession session) {
        if (!StringUtils.isEmpty(username) && "123456".equals(password)){
            session.setAttribute("loginUser",username);
            return ThymeleafViewResolver.REDIRECT_URL_PREFIX+"/main.html";
        }else{
            map.put("msg","用户名密码错误");
            return "login";
        }
    }
}
